<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //补全字符串的长度
        console.log('a'.padStart(5, 'ba')); //babaa
        console.log('x'.padEnd(4, 'd')); //xddd
        //注意事项：当元字符串的长度，等于或大于最大长度，不会消减原来的字符串
        //字符串补全不生效 返回原来的字符串
        console.log('xxx'.padStart(2, 'ab')) //xxx
        console.log('xxx'.padEnd(2, 'ab')) //xxx
            //用来补全的字符串与原字符串长度之和超过了最大的长度
            //截出超出位数的补全字符串，原字符串不动
        console.log('xxx'.padStart(10, '0123456789')); //0123456xxx
        console.log('xxx'.padEnd(10, '0123456789')); //xxx0123456
        //如果省略第二个参数，默认使用空格来填充
        console.log('x'.padStart(4)); //   x
        console.log('x'.padEnd(4)); //x

        //在实际开发中的应用
        //显示日期格式
        //2020-10-10
        //2020-1-2
        console.log('10'.padStart(2, 0));
        console.log('1'.padStart(2, 0));
    </script>
</body>

</html>